//
//  OERegisterDownViewController.m
//  OneEightyNine
//
//  Created by apple on 2019/3/3.
//  Copyright © 2019 stoneobs. All rights reserved.
//

#import "OERegisterDownViewController.h"

@interface OERegisterDownViewController ()
@property(nonatomic, strong) UITextField                     *pwdTextFiled;/**<  */
@property(nonatomic, strong) STButton                     *confimButton;/**<  */
@end

@implementation OERegisterDownViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self configSubView];
    [self addregNotifacations];
    [self st_addAdjustView:self.confimButton offset:10];
    // Do any additional setup after loading the view.
}
- (void)addregNotifacations{
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(st_notifactionMethod:)
                                                 name:UITextFieldTextDidChangeNotification
                                               object:nil];
    
}
- (void)st_notifactionMethod:(NSNotification*)notifacation{
    if (notifacation.object == self.pwdTextFiled) {
        if (self.pwdTextFiled.text.length > 5) {
            self.confimButton.backgroundColor =OE_LIMITE_COLOR;
            self.confimButton.userInteractionEnabled = YES;
        }else{
            self.confimButton.backgroundColor =UIColor.grayColor;
            self.confimButton.userInteractionEnabled = NO;
        }
    }
    
}
- (void)dealloc{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
#pragma mark --configSubView
- (void)configSubView{
    self.tableView.backgroundColor = UIColor.whiteColor;

    UIView * footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 100)];
    
    STLabel * alertLabel = [[STLabel alloc] initWithFrame:CGRectMake(22, 20, UIScreenWidth - 44, 40)
                                                      text:OESTRING(@"SET THE PASSWORD")
                                                 textColor:SecendTextColor
                                                      font:18
                                               isSizetoFit:NO
                                             textAlignment:NSTextAlignmentLeft];
    [footer addSubview:alertLabel];
    
    self.pwdTextFiled = [[UITextField alloc] initWithFrame:CGRectMake(22, alertLabel.bottom + 60, footer.width - 44, 50)];
    self.pwdTextFiled.secureTextEntry = YES;
    self.pwdTextFiled.textColor = SecendTextColor;
    self.pwdTextFiled.placeholder = OESTRING(@"Set the password");
    [self.pwdTextFiled st_showBottomLine];
    [footer addSubview:self.pwdTextFiled];
    
    __weak typeof(self) weakSelf =  self;
    STButton * confimButton = [[STButton alloc] initWithFrame:CGRectMake(5, self.pwdTextFiled.bottom + 80, UIScreenWidth - 30, 44)
                                                        title:OESTRING(@"COMPLETE")
                                                   titleColor:UIColor.whiteColor
                                                    titleFont:15
                                                 cornerRadius:22
                                              backgroundColor:UIColor.grayColor
                                              backgroundImage:nil
                                                        image:nil];
    confimButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    confimButton.centerX = self.tableView.width / 2;
    [footer addSubview:confimButton];
    [confimButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedConfimButton];
    }];
    self.confimButton = confimButton;
    self.confimButton.userInteractionEnabled = NO;
    
    footer.height = self.confimButton.bottom;
    self.tableView.tableFooterView = footer;
}
#pragma mark --Action Method
- (void)onSelctedConfimButton{
    [OERegisterDataController sendRegisterRequestWithMobile:self.phone password:self.pwdTextFiled.text handle:^(BOOL success, NSString *errorString, NSDictionary *resp) {
        if (success) {
            [SVProgressHUD showSuccessWithStatus:OESTRING(@"Registration successful, please login")];
            [self.navigationController popToRootViewControllerAnimated:YES];
        }
    }];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
